clear all

// SET MACROS
global Input  "Y:/limited/Michigan_CTE/funding_change/data_raw"
global Output "Y:/limited/Michigan_CTE/funding_change/output/figures"

qui include "Y:/limited/Michigan_CTE/funding_change/code/analyze/figures/00_colors.do"

// IMPORT DATA
import excel "$Input/CTEx States Concentration Rate by Ninth-Grade Cohort.xlsx", clear firstrow

// RENAME VARIABLES
rename Ninthgradecohort year
rename TN concen1
rename MA concen2
rename WA concen3
rename MI concen4

// CLEAN DATA

// Year
replace year = year + 3

// Weight
gen wt1 = 304900
gen wt2 = 505492
gen wt3 = 440589
gen wt4 = 972739

// RESHAPE DATA
reshape long concen wt, i(year) j(state)

// LABEL VALUES
label define state ///
  1 "TN" ///
  2 "MA" ///
  3 "WA" ///
  4 "MI"

label values state state

// CLEAN DATA
forvalues y = 2011/2019 {
	gen c`y' = (year ==`y' & state == 4)
}
replace c2014 = 0

// Create graph variables
gen cohort = .
gen conc_over_time = .
gen conc_over_time_l95 = .
gen conc_over_time_u95 = .

// EVENT STUDY REGRESSION
reghdfe concen c2011-c2019 [fw=w], a(state year) cluster(state)

// Store estimates
local i = 1
forvalues x = 2012/2019 {
  replace conc_over_time     = 100 * _b[c`x'] in `i'
  replace conc_over_time_l95 = 100 * _b[c`x'] - (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace conc_over_time_u95 = 100 * _b[c`x'] + (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace cohort = `x' in `i'
  local ++i
}

drop if missing(cohort)

// DRAW GRAPH
tw (rarea conc_over_time_l95 conc_over_time_u95 cohort, color("$c1%30") lwidth(none)) ///
   (connected conc_over_time cohort, sort ///
   lc("$c1") mc("$c1")), ///
   scale(1.1) ///
   xline(2014.5 2015.5, lc(gs12) lp(-)) ///
   yline(0, lc(gs11)) ///
   text(13.7 2014.5 "Funding" "increased," "new formula" "announced", placement(0) color(black) box bcolor(white) margin(b=1)) ///
   text(14.4 2015.5 "New" "formula" "applied", placement(0) color(black) box bcolor(white) margin(t=2 b=1)) ///
   xlabel(2012/2019) ///
   xtitle("Cohort Graduation Year", margin(t=2)) ///
   ylabel(-5(5)15, angle(0) glc(gs13) glw(vthin) glp(shortdash) gmax) ///
   ytitle("Percentage Point Change") ///
   legend(off) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(6) ysize(3.25) ///
	  scheme(s2color)

// EXPORT GRAPH


graph save $Output/02b_cross_state_concentration.gph, replace
*graph export $Output/cross_state_concentration.png, replace
